#include "common.h"
#include "channel.h"


static struct channel *channels = NULL;
static uint32_t *channels_bits = NULL;
static int channels_bits_size = 0;
static struct socket_connection *socket_connections = NULL;


extern int init_channels ()
{
    int channels_size = 0;


    /* alloc channels */
    channels_size = sizeof(struct channel *) * MAX_CHANNELS;
    channels = alloc_block(channels_size);
    if (NULL == channels)
    {
        log("FAILURE: init_channels: alloc_block");
        goto error_alloc_block;
    }

    memset(channels, 0, channels_size);



    /* alloc channels bits map */


    /* init socket_connections_header */
    int i;
    for (i = 0; i < MAX_CHANNELS; i++)
    {
        LIST_INIT(&channels[i].socket_connections_list_header);
    }

}




extern int init_socket_connections ()
{
    int ret;


    /* alloc socket connections */
    int socket_connections_size=0;
    socket_connections_size 
        = MAX_SOCKET_CONNECTIONS * sizeof(struct socket_connection)
    socket_connections = alloc_block(socket_connections_size);
    if (NULL == socket_connections)
    {
        goto err_alloc_block_for_socket_connections;
    }

    memset(socket_connections, 0, socket_connections_size);

    int i;
    for (i = 0; i < MAX_SOCKET_CONNECTIONS; i++)
    {
        LIST_INIT(&socket_connections[i].channels_header);
    }

    return 0;

err_alloc_block_for_socket_connections:
    return -1;
}


extern int 


extern int init_channels()
{
    int i;


        
    memset(&channels, 0, sizeof(channels));

        
    struct channel_pointer *channel_pointers = channels.channel_pointers;
    for (i = 0; i < CHANNELS_LIST_COUNT; i++) {
        LIST_INIT(&channel_pointers[i]);
    }

}


extern int init_connections()
{
        
        memset(&connections, 0, sizeof(connections));

        struct connection_header *connection_pointers = connections.connection_pointers;
        for (i = 0; i < CONNECTIONS_LIST_COUNT; i++) {
                LIST_INIT(&connection_pointers[i]);
        }

}
